.TH std::ostream_iterator 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ostream_iterator \- std::ostream_iterator

.SH Synopsis
   Defined in header <iterator>
   template< class T,

             class CharT = char,
             class Traits = std::char_traits<CharT> >                     \fI(until C++17)\fP
   class ostream_iterator

       : public std::iterator<std::output_iterator_tag, void, void,
   void, void>
   template< class T,

             class CharT = char,                                          \fI(since C++17)\fP
             class Traits = std::char_traits<CharT> >

   class ostream_iterator;

   std::ostream_iterator is a single-pass LegacyOutputIterator that writes successive
   objects of type T into the std::basic_ostream object for which it was constructed,
   using operator<<. Optional delimiter string is written to the output stream after
   every write operation. The write operation is performed when the iterator (whether
   dereferenced or not) is assigned to. Incrementing the std::ostream_iterator is a
   no-op.

   In a typical implementation, the only data members of std::ostream_iterator are a
   pointer to the associated std::basic_ostream and a pointer to the first character in
   the delimiter string.

   When writing characters, std::ostreambuf_iterator is more efficient, since it avoids
   the overhead of constructing and destructing the sentry object once per character.

.SH Member types

   Member type       Definition
   iterator_category std::output_iterator_tag
   value_type        void
   difference_type   void           \fI(until C++20)\fP
                     std::ptrdiff_t \fI(since C++20)\fP
   pointer           void
   reference         void
   char_type         CharT
   traits_type       Traits
   ostream_type      std::basic_ostream<CharT, Traits>

   Member types iterator_category, value_type, difference_type, pointer
   and reference are required to be obtained by inheriting from           \fI(until C++17)\fP
   std::iterator<std::output_iterator_tag, void, void, void, void>.

.SH Member functions

   constructor     constructs a new ostream_iterator
                   \fI(public member function)\fP
   destructor      destructs an ostream_iterator
                   \fI(public member function)\fP
   operator=       writes an object to the associated output sequence
                   \fI(public member function)\fP
   operator*       no-op
                   \fI(public member function)\fP
   operator++      no-op
   operator++(int) \fI(public member function)\fP

.SH Example


// Run this code

 #include <iostream>
 #include <iterator>
 #include <numeric>
 #include <sstream>

 int main()
 {
     std::istringstream str("0.11 0.22 0.33 0.44");

     std::partial_sum(std::istream_iterator<double>(str),
                      std::istream_iterator<double>(),
                      std::ostream_iterator<double>(std::cout, ", "));
     std::cout << '\\n';
 }

.SH Output:

 0.11, 0.33, 0.66, 1.1,

.SH See also

                                     output iterator that writes to
   ostreambuf_iterator               std::basic_streambuf
                                     \fI(class template)\fP
   istream_iterator                  input iterator that reads from std::basic_istream
                                     \fI(class template)\fP
                                     an output iterator that writes successive elements
   std::experimental::ostream_joiner into an output stream, separating adjacent
   (library fundamentals TS v2)      elements with a delimiter
                                     \fI(class template)\fP
